<?php
/*
	本插件：$this->model('licai')->方法名();
	其他地方调用：model('jy_stpinggou/licai')->方法名();
*/
namespace jy_stpinggou;
defined('BY_JYA') or exit('error');
class licai extends \plugin{
	/*
		支付成功
	*/
	public function log_pay($params,$groupid=0){
		$update=array(
			'paytype'=>$params['paytype'],
			'transid'=>$params['transid'],
			'status'=>1,
			'ispay'=>1,
			'paytime'=>TIMESTAMP,
		);
		pdo_update('jy_stpinggou_licailog',$update,array('id'=>$params['id']));
		$group=pdo_get('jy_stpinggou_licaigroup',array('uniacid'=>$_SESSION['uniacid'],'id'=>$groupid));
		//出局人数
		$chuju=pdo_get('jy_stpinggou_licailog',array('isjihuo'=>1,'uniacid'=>$_SESSION['uniacid'],'groupid'=>$groupid),'','id desc');
		$newparams=array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'groupid'=>$groupid);
		if($chuju['id']){
			$newparams['id >']=$chuju['id'];
		}
		$status1=pdo_count('jy_stpinggou_licailog',$newparams);
		//$nums=$group['mannum']*($chujunum+1);
		if($status1>=$group['mannum']){
			//激活一人出局
			pdo_update('jy_stpinggou_licailog',array('isjihuo'=>1),array('id'=>$params['id']));
			$uplog=pdo_get('jy_stpinggou_licailog',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'groupid'=>$groupid),'','id asc');
			$this->uplicai($uplog);
		}
		return true;
	}
	//获利出局
	public function uplicai($log){
		if($log['getfee']>0){
			model('core/member')->member_credit($log['mid'],'credit2',$log['getfee'],true,'jy_stpinggou','倍财金获利出局');
			$feelog=array(
				'mid'=>$log['mid'],
				'groupid'=>$log['groupid'],
				'msg'=>'倍财金出局奖励',
				'fee'=>$log['getfee'],
				'gift_type'=>2,
				'status'=>0,
			);
			$this->model('model')->set_feelog($feelog,2);
		}
		pdo_update('jy_stpinggou_licailog',array('status'=>2,'gettime'=>TIMESTAMP),array('id'=>$log['id']));
		return true;
	}
	//兑换红包
	public function duiredfee($getfee,$mid=0){
		$mid=$mid?:$_SESSION['uid'];
		if($getfee>0){
			model('core/member')->member_credit($mid,'credit2',$getfee,true,'jy_stpinggou','兑换拼中红包');
			$feelog=array(
				'mid'=>$mid,
				'msg'=>'兑换拼中红包',
				'fee'=>$getfee,
				'gift_type'=>2,
				'status'=>0,
			);
			$this->model('model')->set_feelog($feelog,2);
			pdo_update('jy_stpinggou_member',array('baofee -='=>$this->fenxiaoset['xiao_beifee'],'jiafee -='=>$this->fenxiaoset['xiao_jiafee']),array('mid'=>$mid));
		}
		return true;
	}
}
?>